/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import domain.Products;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import services.impl.ProductsServices;

/**
 *
 * @author amega
 */
@ManagedBean(name="productsBean")
@SessionScoped
public class ProductsBean {
    
    @EJB
    private ProductsServices productsServices;
    
    private List<Products>  allProducts = new ArrayList<Products>();
    
    private Products newProducts = new Products();
    
    
    
    private Products selectProducts;

    private String[] typeProducts = {
        "суп", "мясное блюдо","салат","Фокачча и Хлеб", "алкогольный  напиток","пицца","десерт"
    };

    public String[] getTypeProducts() {
        return typeProducts;
    }
    
    
    
    public List<Products> getAllProducts() {
        
        allProducts = productsServices.findAll();
       
        return allProducts;
    }

    public void setAllProducts(List<Products> allProducts) {
        this.allProducts = allProducts;
    }

    public Products getNewProducts() {
        return newProducts;
    }

    public void setNewProducts(Products newProducts) {
        this.newProducts = newProducts;
    }

    public Products getSelectProducts() {
        return selectProducts;
    }

    public void setSelectProducts(Products selectProducts) {
        this.selectProducts = selectProducts;
    }
    
    public void saveProducts(){
       
        productsServices.create(newProducts);
        newProducts = new Products();
    }
    
    public void deleteProducts() {
        productsServices.remove(selectProducts);
    }
    
    public void editProducts() {
        System.out.println("binding "+selectProducts.getName());
        productsServices.edit(selectProducts);
    }


}
